package org.dreamwork.modbus.tcp.protocol;

public class MBAP {
    /** 事务处理标识符 */
    public int transaction;

    /** 对于 Modbus TCP 而言， protocol 恒为零 */
    public int protocol = 0;

    /** 后续报文长度 */
    public int length;

    /** 单元标识符 */
    public int unit = 0xff;

    public byte[] toByteArray () {
        byte[] buff = new byte[7];
        buff[0] = (byte) ((transaction >> 8) & 0xff);
        buff[1] = (byte) (transaction & 0xff);
        buff[2] = buff[3] = 0;
        buff[4] = (byte) ((length >> 8) & 0xff);
        buff[5] = (byte) (length & 0xff);
        buff[6] = (byte) unit;
        return buff;
    }
}
